Using Graphics Devices
To use graphics devices, your application generally uses the QuickDraw routines described elsewhere in this book to draw images into a window; Color QuickDraw automatically displays your images in a manner appropriate for each graphics device that contains a portion of that window.
The pixel map for a window's color graphics port always consists of the pixel depth, color table, and boundary rectangle of the main screen, even if the window is created on or moved to an entirely different screen.
Instead of drawing directly into an onscreen graphics port, your application can use an offscreen graphics world (described in the chapter "Offscreen Graphics Worlds") to create images with the ideal pixel depth and color table required by your application. Then your application can use the
CopyBits
procedure to copy the images to the screen. Color QuickDraw converts the colors of the images for appropriate display on grayscale graphics devices and on direct and indirect color graphics devices. The manner in which Color QuickDraw translates the colors specified by your application to different graphics devices is described in the chapter "Color QuickDraw." However, if Color QuickDraw were to translate the colors of a color wheel (such as that used by the Color Picker, described in
Inside Macintosh: Advanced Color Imaging
), the image would appear as solid black on a black-and-white screen.
Many applications can let Color QuickDraw manage multiple video devices of differing dimensions and pixel depths. If your application needs more control over video device management--if it needs certain pixel depths or sets of colors to function effectively, for example--you can take several steps.
-
If you need to know about the characteristics of available video devices, your application can use the
GetDeviceList
function to obtain a handle to the first
GDevice
record in the device list, the
GetGDevice
function to obtain a handle to the
GDevice
record for the current device, the
GetMainDevice
function to obtain a handle to the
GDevice
record for the main screen, or the
GetMaxDevice
function to obtain a handle to the
GDevice
record for the graphics device with the greatest pixel depth. Your application can then pass this handle to a routine like the
TestDeviceAttribute
function or the
HasDepth
function to determine various characteristics of a video device, or your application can examine the
gdRect
field of the
GDevice
record to determine the dimensions of the screen it represents.
-
If you want to optimize your application's drawing for the best possible display on whatever type of screen is the current device, your application can use the
DeviceLoop
procedure, described on
DeviceLoop
, to determine the capabilities of the current device before drawing into a window on that device.
-
If the current device is not suitable for the proper display of an image--for example, if the user has moved the window for your multicolored display of national flags to a black-and-white screen--your application can display the best image possible and display a message explaining that a more capable screen is required for better presentation of the image. Your application can use the
DeviceLoop
procedure to determine the capabilities of the current device.
-
If your application uses the
HasDepth
function to determine that the current device can support the pixel depth required for the proper display of your image, but the
DeviceLoop
procedure indicates that the user has changed the screen's display, your application can use the
SetDepth
function to change the pixel depth of the screen. Note that the
SetDepth
function is provided for applications that are able to run only on graphics devices of a particular depth. Your application should use it only after soliciting the user's permission with a dialog box.
-
If your application needs more control over colors on different indexed devices, your application can use the Palette Manager to arrange different sets of colors for particular images. Because the CLUT is variable on most video devices, your application can display up to 16 million colors, although on an 8-bit indexed device, for example, only 256 different colors can appear at once. See the chapter "Palette Manager" in
Inside Macintosh: Advanced Color Imaging
for more information.
-
If your application needs to work with offscreen images that have characteristics different from those on the available graphics devices, your application can create offscreen graphics worlds, which contain their own
GDevice
records. See the chapter "Offscreen Graphics Worlds" in this book for more information.
To use the routines described in this chapter, your application must check for the existence of Color QuickDraw by using the
Gestalt
function with the
gestaltQuickDrawVersion
selector. The
Gestalt
function returns a 4-byte value in its
response
parameter; the low-order word contains QuickDraw version data. In that low-order word, the high-order byte gives the major revision number and the low-order byte gives the minor revision number. If the value returned in the
response
parameter is greater than or equal to the value of the constant
gestalt32BitQD
, then the system supports Color QuickDraw and all of the routines described in this chapter.
© 1997 Apple Computer, Inc.Previous | Chapter Top | Chapter Contents | Next